//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>

// Time

#define T_MINUTE 60
#define T_HOUR   (60 * T_MINUTE)
#define T_DAY    (24 * T_HOUR)
#define T_5_DAYS (5 * T_DAY)
#define T_WEEK   (7 * T_DAY)
#define T_MONTH  (30.5 * T_DAY)
#define T_YEAR   (365 * T_DAY)

typedef struct {
    NSUInteger year;
    NSUInteger month;
    NSUInteger week;
} YearMonthWeekNumberStruct;

@interface NSDate (Extensions)

/**
 * Returns the current date with the time set to midnight.
 */
+ (NSDate *)dateWithToday;

/**
 * Returnes the local date with utc date.
 */
+ (NSDate *)dateWithUTCString:(NSString *)UTCString;

/**
 * Returns the current date and time.
 */
//+ (NSDate *)timestampWithToday;

/**
 * Returns the current date string.
 */
//+ (NSString *)stringOfToday;

/**
 * Returns the string of give NSDate by designated separator
 */
+ (NSString *)stringOfDate:(NSDate *)date withSeparator:(NSString *)separator;

/**
 * Returns the date of give date string by designated format string.
 */
+ (NSDate *)dateWithString:(NSString *)dateString format:(NSString *)format;
/**
 * Returns the current date.
 */
//+ (NSDate *)dateOfToday;

// 返回给定日期是当月的第几周(周一是第1天)
+ (NSUInteger)weekNumberOfMonthWithDay:(NSDate *)date;

// 返回给定日期当月的最大周数(周一是第1天)
+ (NSUInteger)maxWeekNumberOfMonthWithDay:(NSDate *)date;

// 返回给定日期当月的第X周的开始时间(周一是第1天, 周数从0开始, 比如第0周)
+ (NSDate *)firstDayNumWeek:(NSUInteger)numWeek month:(NSDate *)month;

// 返回给定日期当月的第X周的结束时间(周日是最后1天, 周数从0开始, 比如第0周)
+ (NSDate *)endDayNumWeek:(NSUInteger)numWeek month:(NSDate *)month;

// 设置某天的时间, 例如:18:00:00 传入180000 (必须包含秒, 且为24小时制)
+ (NSDate *)setupTimeWithThatDay:(NSDate *)date format:(NSString *)format;

// 返回某天是一年中的第几周
+ (NSArray<NSNumber *> *)weekNumberOfYearWithDay:(NSDate *)date;

// 返回某天上一周是一年中的第几周
+ (NSArray<NSNumber *> *)lastWeekNumberOfYear;

// 返回给定日期是某月的第几周(当月的前几天有可能是上个月的最后1周, 周一是第1天)
+ (YearMonthWeekNumberStruct)specialWeekNumberOfMonthWithDay:(NSDate *)date;

- (BOOL)isTodayTime;

- (BOOL)isYesterdayTime;

- (BOOL)isEarlierThanDate:(NSDate *)anotherDate;

- (BOOL)isLaterThanDate:(NSDate *)anotherDate;

/**
 * Returns a copy of the date with the time set to midnight on the same day.
 */
- (NSDate *)dateAtMidnight;

/**
 * Formats the date with 'h:mm a' or the localized equivalent.
 */
- (NSString *)formatTime;

// 返回24小时制的时间, 比如: 18:01
- (NSString *)format24HourTime;

/**
 * Formats the date with 'EEEE, LLLL d, YYYY' or the localized equivalent.
 */
- (NSString *)formatDate;

/**
 * Formats the date with 'yyyy-MM-dd HH:mm:ss'.
 */
- (NSString *)formatDateTimeWithSeparator:(NSString *)sp;

/**
 * Formats the date with 'yyyy-MM-dd'.
 */
- (NSString *)formatDateWithSeparator:(NSString *)sp;

/**
 * Formats the date according to how old it is.
 *
 * For dates less than a day old, the format is 'h:mm a', for less than a week old the
 * format is 'EEEE', and for anything older the format is 'M/d/yy'.
 */
- (NSString *)formatShortTime;

/**
 * Formats the date according to how old it is.
 *
 * For dates less than a day old, the format is 'h:mm a', for less than a week old the
 * format is 'EEE h:mm a', and for anything older the format is 'MMM d h:mm a'.
 */
- (NSString *)formatDateTime;

/**
 * Formats dates within 24 hours like '5 minutes ago', or calls formatDateTime if older.
 */
- (NSString *)formatRelativeTime;

/**
 * Formats dates within 1 week like '5m' or '2d', or calls formatShortTime if older.
 */
- (NSString *)formatShortRelativeTime;

/**
 * Formats the date with 'MMMM".
 */
- (NSString *)formatMonth;

/**
 * Formats the date with 'yyyy".
 */
- (NSString *)formatYear;

/**
 * Formats the date with format string.
 */
- (NSString *)formatDateByFormatString:(NSString *)format;

- (NSString *)getHourSegment;

- (NSDate *)offsetMonth:(NSInteger)numMonths;

- (NSDate *)offsetDay:(NSInteger)numDays;

- (NSDate *)offsetMinute:(NSUInteger)numMinutes;

- (NSDate *)offsetSecond:(NSUInteger)seconds;

- (NSString *)UTCString;

- (NSString *)formatDateToLocalizedString;

- (NSString *)formatSocialShortTime;

- (NSString *)formatSocialLongTime;

- (NSString *)formatSocialTimeByAddingTime:(BOOL)addingTime todayStringFormat:(NSString *)todayStringFormat otherYearFormat:(NSString *)otherYearFormat;

// 返回日期和星期, 例如: 2016.02.24 星期三
- (NSString *)formatWeekDate;

// 返回星期, 例如: 星期三
- (NSString *)formatWeek;

// 判断日期是不是在某个范围内
- (BOOL)dateInWeek:(CGFloat)week month:(CGFloat)month hour:(CGFloat)hour minute:(CGFloat)minute;

// 返回当周的周一(周一是第1天)
- (NSDate *)monday;

// 返回当周的周日(周一是第1天)
- (NSDate *)sunday;

// 返回当月的第1天(周一是第1天)
- (NSDate *)firstDayOfMonth;

// 返回当月的最后1天(周一是第1天)
- (NSDate *)endDayOfMonth;

// 计算星座
- (NSString *)constellation;

+ (NSTimeInterval)createYourNeedYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day ;

+ (NSInteger)thisYearNumber;

- (NSDateComponents *)toYearMonthDayDateComponents;

@end
